<?php

namespace Weapp\Product;

use Weapp\Basic\Basic;

/**
 * spu接口
 * Class Spu
 * @url https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent/API/spu/spu_readme.html
 * @package Weapp/Product
 */
class Spu extends Basic
{
    /**
     * 添加商品
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function add($data)
    {
        $url = 'product/spu/add';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }

    /**
     * 删除
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function del($data)
    {
        $url = 'product/spu/del';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }

    /**
     * 获取商品
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function get($data)
    {
        $url = 'product/spu/get';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 获取商品列表
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function get_list($data)
    {
        $url = 'product/spu/get_list';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 搜索商品
     * 注意：目前只能搜到到status=5的已上架商品
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function search($data)
    {
        $url = 'product/spu/search';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 更新商品
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function update($data)
    {
        $url = 'product/spu/update';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 上架商品
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function listing($data)
    {
        $url = 'product/spu/listing';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 下架商品
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function delisting($data)
    {
        $url = 'product/spu/delisting';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 添加抢购任务
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function limiteddiscount_add($data)
    {
        $url = 'https://api.weixin.qq.com/product/limiteddiscount/add/access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 获取抢购任务列表
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function limiteddiscount_get_list($data)
    {
        $url = 'https://api.weixin.qq.com/product/limiteddiscount/get_list/access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
    /**
     * 更新抢购任务
     * @param array $data
     * @return array
     * @throws \Weapp\Exceptions\InvalidResponseException
     * @throws \Weapp\Exceptions\LocalCacheException
     */
    public function limiteddiscount_update_status($data)
    {
        $url = 'https://api.weixin.qq.com/product/limiteddiscount/update_status/access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->callPostApi($url, $data, true);
    }
}
